export function useExamData() {
  const monthNames = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'];
  function formatDateStr(dateStr: string): string {
    const monthStr = dateStr.substring(0, 2);
    const dayStr = dateStr.substring(2);
    const monthNum = Number.parseInt(monthStr, 10);
    const dayNum = Number.parseInt(dayStr, 10);
    const monthName = monthNames[monthNum - 1];
    return `${monthName}${dayNum}日`;
  }
  const getExamData = (newData: any): any => {
    const data = ref<any[]>([]);
    for (let i = 0; i < newData.value.length; i++) {
      const itemId = newData.value[i].id;
      let str = '';
      if (newData.value[i].examDate !== '' && newData.value[i].examDate !== null && newData.value[i].examDate !== undefined) {
        const month = useExamData().monthNames[Number.parseInt(newData.value[i].examDate.substring(0, 2), 10) - 1];
        str += `${month}份`;
      }
      // else {
      //   const month = useExamData().monthNames[Number.parseInt(newData.value[i].examDate.substring(0, 2), 10) - 1];
      //   str += `${month}份`;
      // }
      if (newData.value[i].examLevel !== '' && newData.value[i].examLevel !== null && newData.value[i].examLevel !== undefined) {
        str += `${newData.value[i].examLevel}:`;
      }
      if (newData.value[i].registrationStartDate !== '' && newData.value[i].registrationStartDate !== null && newData.value[i].registrationStartDate !== undefined) {
        str += `考试报名开始日期${useExamData().formatDateStr(newData.value[i].registrationStartDate)}`;
        if ((newData.value[i].registrationDeadline !== '' && newData.value[i].registrationDeadline !== null && newData.value[i].registrationDeadline !== undefined) || (newData.value[i].examDate !== '' && newData.value[i].examDate !== null && newData.value[i].examDate !== undefined)) {
          str += ',';
        }
      }
      if (newData.value[i].registrationDeadline !== '' && newData.value[i].registrationDeadline !== null && newData.value[i].registrationDeadline !== undefined) {
        str += `考试报名截止日期${useExamData().formatDateStr(newData.value[i].registrationDeadline)}`;
        if (newData.value[i].examDate !== '' && newData.value[i].examDate !== null && newData.value[i].examDate !== undefined) {
          str += ',';
        }
      }
      if (newData.value[i].examDate !== '' && newData.value[i].examDate !== null && newData.value[i].examDate !== undefined) {
        str += `考试日期${useExamData().formatDateStr(newData.value[i].examDate)}`;
      }
      if (newData.value[i].examEvent !== '' && newData.value[i].examEvent !== null && newData.value[i].examEvent !== undefined) {
        str += `(${newData.value[i].examEvent})`;
      }
      const dataItem = {
        id: itemId,
        str,
      };
      data.value.push(dataItem);
    }
    return data.value;
  };
  return {
    monthNames,
    formatDateStr,
    getExamData,
  };
}
